<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    function getDay(year, month, day) {
        dayNum = day; //总天数
        for (let i = 1; i < month; i++) {
            dayNum += monthDayNum(year, i);
        }

        return dayNum;
    }

    function febDayNum(year) {
        //闰年二月29天
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            return 29;
        } else { //平年二月28天
            return 28;
        }
    }

    function monthDayNum(year, month) {
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                return 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
                break;
            case 2:
                return febDayNum(year);
                break;
        }
    }


    console.log(getDay(2021, 10, 17));
</script>

</html>